module.exports = function ($scope, $modalInstance, $resource, toaster, obj, FileUploader, date2str){
    
    $scope.obj = obj;
	$scope.date = {
        //'lable': date2str(new Date()),
		'opened': false,
        'opened1': false,
        'lable' : obj.collection_company_start_date,
        'lable1' : obj.collection_company_end_date
	}

    //保存
	$scope.save = function() {
		$scope.obj.collection_company_start_date = date2str($scope.date.lable);
		$scope.obj.collection_company_end_date = date2str($scope.date.lable1);
		//if(!checkInfo($scope.obj)) return;
		$resource('/api/as/goc/enterpriserecord/updatecollection', {}, {}).save($scope.obj, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
    
    //校验采集信息
	// function checkInfo(company){
	// 	if(!company.company_code){
	// 		toaster.warning({title: '', body: '请填写统一社会信用代码.'});
	// 		return false;
	// 	}
	// 	if(!company.business_license_code){
	// 		toaster.warning({title: '', body: '请填写营业执照编号.'});
	// 		return false;
	// 	}
	// 	if(!company.registered_address){
	// 		toaster.warning({title: '', body: '请填写企业注册地址.'});
	// 		return false;
	// 	}
	// 	if(!company.company_type){
	// 		toaster.warning({title: '', body: '请填写公司类型.'});
	// 		return false;
	// 	}
	// 	if(!company.registered_capital){
	// 		toaster.warning({title: '', body: '请填写注册资金汉字大写.'});
	// 		return false;
	// 	}
	// 	if(!company.company_start_date){
	// 		toaster.warning({title: '', body: '请填写成立时间.'});
	// 		return false;
	// 	}
	// 	if(!company.company_end_date){
	// 		toaster.warning({title: '', body: '请填写营业期限.'});
	// 		return false;
	// 	}
	// 	if(!company.phone){
	// 		toaster.warning({title: '', body: '请填写公司电话、传真.'});
	// 		return false;
	// 	}
	// 	if(!company.company_email){
	// 		toaster.warning({title: '', body: '请填写公司邮箱.'});
	// 		return false;
	// 	}
	// 	if(!company.responsible_name){
	// 		toaster.warning({title: '', body: '请填写负责人名字.'});
	// 		return false;
	// 	}
	// 	if(!company.responsible_no){
	// 		toaster.warning({title: '', body: '请填写负责人身份证号.'});
	// 		return false;
	// 	}
	// 	if(!company.responsible_mobile){
	// 		toaster.warning({title: '', body: '请填写负责人手机.'});
	// 		return false;
	// 	}
	// 	if(!/^1[3|5|7|8|9]\d{9}$/.test(company.responsible_mobile)){
	// 		toaster.warning({title: '', body: '手机号格式不正确'});
	// 		return false;
	// 	}
	// 	if(!company.contact_address){
	// 		toaster.warning({title: '', body: '请填写联系地址.'});
	// 		return false;
	// 	}
	// 	if(!company.juridical_person){
	// 		toaster.warning({title: '', body: '请填写法人.'});
	// 		return false;
	// 	}
	// 	if(!company.business_scope){
	// 		toaster.warning({title: '', body: '请填写经营范围.'});
	// 		return false;
	// 	}
	// 	if(!company.business_license_img_url){
	// 		toaster.warning({title: '', body: '请上传营业执照图片.'});
	// 		return false;
	// 	}
	// 	return true;
	// }
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }

    //上传图片
	var uploader = $scope.uploader = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
    });
    uploader.filters.push({
        name: 'imageFilter',
        fn: function(item /*{File|FileLikeObject*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
	});
	uploader.onSuccessItem = function(fileItem, response, status, headers) {
        $scope.obj.collection_business_license_img_url = response.savename;
    };

    $scope.dateOpen = function ($event, item) {
		console.log('open');
		$event.preventDefault();
		$event.stopPropagation();
		item.opened = true;
	};

	$scope.dateOpen1 = function ($event, item) {
		console.log('open');
		$event.preventDefault();
		$event.stopPropagation();
		item.opened1 = true;
	};

};